package com.program.wechatmall.controller.userManagement;

import com.program.wechatmall.bean.BaseResponseVo;
import com.program.wechatmall.bean.userManagement.LoginBO;
import com.program.wechatmall.bean.userManagement.UserManagementVO;
import com.program.wechatmall.service.userManagement.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author: chengxin
 * @Date :  2020/8/31 19:45
 * @Version 1.0
 */
@RestController
@RequestMapping("admin")
public class AdminController {
    @Autowired
    AdminService adminServiceImpl;

//    @RequestMapping("queryAdminById/{id}")
//    public BaseResponseVo queryAdminById(@PathVariable("id") Integer id) {
//        Admin admin = adminServiceImpl.queryAdminById(id);
//        if (admin != null) {
//            return BaseResponseVo.ok(admin);
//        }
//        return BaseResponseVo.fail();
//    }
    /**
     *管理员登录
     * 在使用shiro之前，暂时使用，不要模仿
     */
    //TODO
    @RequestMapping("auth/login")
    public BaseResponseVo login(@RequestBody LoginBO loginBO) {
        //没有使用shiro的情况下，返回任意的这个值就行了
        //errno = 0
        BaseResponseVo<Object> baseRespVO = new BaseResponseVo<>();
        baseRespVO.setErrno(0);
        baseRespVO.setData("abc");
        baseRespVO.setMsg("成功");
        return baseRespVO;

    }
    /**
     * 管理员登录后页面信息
     * 在使用shiro之前，暂时使用，不要模仿
     */
    //TODO
    @RequestMapping("auth/info")
    public BaseResponseVo info() {
        BaseResponseVo<Object> baseRespVO = new BaseResponseVo<>();
        baseRespVO.setErrno(0);
        baseRespVO.setMsg("成功");
        HashMap<Object, Object> map = new HashMap<>();
        map.put("name", "admin123");
        map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        ArrayList<Object> roleList = new ArrayList<>();
        roleList.add("超级管理员");
        ArrayList permList = new ArrayList<>();
        permList.add("*");

        map.put("roles", roleList);
        map.put("perms", permList);
        baseRespVO.setData(map);

        return baseRespVO;
    }
    /**
     * 会员管理
     */
    @RequestMapping("user/list")
    public BaseResponseVo memberManagement(@RequestParam("page") Integer page,
                                           @RequestParam("limit") Integer limit,
                                           @RequestParam("sort") String addTime,
                                           @RequestParam("order") String order) {
        UserManagementVO userManagementVO = adminServiceImpl.queryAllUsersInfo(page, limit, addTime, order);
        return BaseResponseVo.ok(userManagementVO);

    }

}
